package cn.uexpo.lhz.biz.impl;

import java.util.List;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;



import cn.uexpo.lhz.biz.DictionaryItemBiz;
import cn.uexpo.lhz.common.oldBase.BOException;
import cn.uexpo.lhz.common.oldUtils.PageRequest;
import cn.uexpo.lhz.common.oldUtils.PageResult;
import cn.uexpo.lhz.common.oldUtils.PageUtils;
import cn.uexpo.lhz.dao.DictionaryItemMapper;
import cn.uexpo.lhz.domain.DictionaryItem;
import cn.uexpo.lhz.domain.DictionaryItemExample;

@Transactional
@Service
public class DictionaryItemBizImpl implements DictionaryItemBiz {

	@Autowired
	private DictionaryItemMapper dictionaryItemMapper;

	@Override
	public int insert(DictionaryItem record) {
		// TODO Auto-generated method stub
		return dictionaryItemMapper.insert(record);
	}

//	@Override
//	public int delete(DictionaryItem record) {
//		// TODO Auto-generated method stub
//		return dictionaryItemMapper.deleteByPrimaryKey(record.getId());
//	}

	@Override
	public int delete(List<DictionaryItem> records) {
		for (DictionaryItem record : records) {
			dictionaryItemMapper.deleteByPrimaryKey(record.getId());
		}
		return 1;
	}

//	@Override
//	public int update(DictionaryItem record) {
//		// TODO Auto-generated method stub
//		return dictionaryItemMapper.updateByPrimaryKey(record);
//	}

	@Override
	public int updateByPrimaryKeySelective(DictionaryItem record) throws BOException {
		// TODO Auto-generated method stub
		return dictionaryItemMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public DictionaryItem selectByPrimaryKey(Integer id) {
		// TODO Auto-generated method stub
		return dictionaryItemMapper.selectByPrimaryKey(id);
	}

	@Override
	public long countByExample(DictionaryItemExample example) throws BOException {
		// TODO Auto-generated method stub
		return dictionaryItemMapper.countByExample(example);
	}

	@Override
	public List<DictionaryItem> selectByExample(DictionaryItemExample example) throws BOException {
		// TODO Auto-generated method stub
		return dictionaryItemMapper.selectByExample(example);
	}

	@Override
	public PageResult findPage(PageRequest pageRequest, DictionaryItemExample example) throws BOException {

		int pageNum = pageRequest.getPage();
		int pageSize = pageRequest.getLimit();
		PageHelper.startPage(pageNum, pageSize);
		List<DictionaryItem> records = (List<DictionaryItem>) dictionaryItemMapper.selectByExample(example);
		return PageUtils.getPageResult(pageRequest, new PageInfo<DictionaryItem>(records));
	}

	@Override
	public DictionaryItem selectByUniqueCode(String uniqueCode) throws BOException {

		DictionaryItem item = null;
		DictionaryItemExample example = new DictionaryItemExample();
		DictionaryItemExample.Criteria citeria = example.createCriteria();
		citeria.andItemcodeEqualTo(uniqueCode);
		List<DictionaryItem> items = dictionaryItemMapper.selectByExample(example);
		if (items != null && items.size() > 0) {
			item = items.get(0);
		}
		return item;
	}

//	=================================================================================================================================================
	@Override
	public int insertSelective(DictionaryItem record) throws BOException {
		// TODO Auto-generated method stub
		return dictionaryItemMapper.insertSelective(record);
	}

	@Override
	public int deleteByPrimaryKey(Integer id) throws BOException {
		// TODO Auto-generated method stub
		return dictionaryItemMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int deleteEntity(DictionaryItem record) throws BOException {
		// TODO Auto-generated method stub
		return dictionaryItemMapper.deleteByPrimaryKey(record.getId());
	}

	@Override
	public int deleteByIds(List<Integer> ids) throws BOException {
		// TODO Auto-generated method stub
		for (Integer id : ids) {
			dictionaryItemMapper.deleteByPrimaryKey(id);
		}
		return 1;
	}

	@Override
	public int deleteByExample(DictionaryItemExample example) throws BOException {
		// TODO Auto-generated method stub
		return dictionaryItemMapper.deleteByExample(example);
	}

	@Override
	public int updateByPrimaryKey(DictionaryItem record) throws BOException {
		// TODO Auto-generated method stub
		return dictionaryItemMapper.updateByPrimaryKey(record);
	}

	@Override
	public int updateByExampleSelective(DictionaryItem record, DictionaryItemExample example) throws BOException {
		// TODO Auto-generated method stub
		return dictionaryItemMapper.updateByExampleSelective(record,example);
	}

	@Override
	public int updateByExample(DictionaryItem record, DictionaryItemExample example) throws BOException {
		// TODO Auto-generated method stub
		return dictionaryItemMapper.updateByExample(record,example);
	}

}
